package o;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.DrawableRes;
import androidx.annotation.StringRes;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.card.base.bean.BaseDistCardBean;
import com.huawei.appgallery.foundation.ui.framework.widget.button.DownloadButton;
import com.huawei.appgallery.share.api.ShareBean;
import com.huawei.appgallery.share.protocol.WXEntryActivityProtocol;
import com.huawei.appgallery.share.protocol.WXEntryActivityProtocol.Request;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import o.cwj.c;
import o.cwj.i;
import o.dge.d;

public class cxn extends cxg {
    private String ʻ;
    private BroadcastReceiver ʼ = new BroadcastReceiver(this) {
        final /* synthetic */ cxn ˏ;

        {
            this.ˏ = r1;
        }

        public void onReceive(Context context, Intent intent) {
            if (this.ˏ.ॱ != null) {
                this.ˏ.ॱ.ॱ();
            }
        }
    };
    private cxi ˊ;
    private ShareBean ˋ;
    private boolean ˎ;
    private IWXAPI ˏ;
    private DownloadButton ॱ;
    private cxd ᐝ = new cxd(this) {
        final /* synthetic */ cxn ˏ;

        {
            this.ˏ = r1;
        }

        public void ˎ(Context context, String str, String str2) {
            this.ˏ.ʻ = str2;
            this.ˏ.ʼ();
            dgh.onEvent(new d(ContentManager.getInstant().getContext(), i.ˎ).ˏ(this.ˏ.ᐝ() + '|' + UserSession.getInstance().getUserId() + '|' + this.ˏ.ˋ.ʻ()).ˋ());
            this.ˏ.ˏ(context);
        }
    };

    protected class e extends AsyncTask<Void, Void, byte[]> {
        final /* synthetic */ cxn ˊ;
        private Bitmap ˏ;
        private Context ॱ;

        protected /* synthetic */ Object doInBackground(Object[] objArr) {
            return ˎ((Void[]) objArr);
        }

        protected /* synthetic */ void onPostExecute(Object obj) {
            ˋ((byte[]) obj);
        }

        e(cxn o_cxn, Context context, Bitmap bitmap) {
            this.ˊ = o_cxn;
            this.ॱ = context;
            this.ˏ = bitmap;
        }

        protected byte[] ˎ(Void... voidArr) {
            return cxw.ˎ(this.ॱ, this.ˏ, this.ˊ.ˋ.ˏ(), 30, cxw.ˏ(this.ˊ.ˋ.ˋ()));
        }

        protected void ˋ(byte[] bArr) {
            this.ˊ.ॱ(this.ॱ, bArr);
        }
    }

    public String ˎ() {
        return "com.tencent.mm";
    }

    public boolean ˊ(ShareBean shareBean) {
        return super.ॱ(shareBean.ͺ(), 8, shareBean.ˏॱ());
    }

    @StringRes
    protected int ˊ() {
        return i.ʽॱ;
    }

    @DrawableRes
    protected int ʻ() {
        return cwj$b.ʼ;
    }

    public boolean ˏ(cxi o_cxi, LinearLayout linearLayout, LayoutInflater layoutInflater, boolean z, ShareBean shareBean) {
        this.ˊ = o_cxi;
        this.ˋ = shareBean;
        View inflate = layoutInflater.inflate(cwj.d.ˊ, null);
        ((TextView) inflate.findViewById(c.ˋ)).setText(ˊ());
        ((ImageView) inflate.findViewById(c.ॱ)).setImageResource(ʻ());
        this.ॱ = (DownloadButton) inflate.findViewById(c.ʽ);
        o_cxi.ˋ(ˎ(), this.ॱ);
        linearLayout.addView(inflate);
        inflate.setOnClickListener(new evx(this) {
            final /* synthetic */ cxn ˎ;

            {
                this.ˎ = r1;
            }

            public void ˋ(View view) {
                cwr.ॱ.ˋ("WeixinFriendsShare", "click share to weixin friend !");
                if (!doo.ˊ(this.ˎ.ˊ.ᐝ())) {
                    cwr.ॱ.ˋ("WeixinFriendsShare", "no available network.");
                    evk.ˏ(this.ˎ.ˊ.ᐝ(), i.ʻ, 0).ˋ();
                } else if (cxp.ˏ(this.ˎ.ˊ.ᐝ(), this.ˎ.ˎ())) {
                    cxo.ˎ(this.ˎ.ˊ.ᐝ().getString(i.ॱˎ), this.ˎ.ˊ.ᐝ(), this.ˎ.ᐝ);
                } else {
                    cwr.ॱ.ˋ("WeixinFriendsShare", "Weixin not installed.Show Download Button");
                    this.ˎ.ॱ(this.ˎ.ˊ.ᐝ());
                }
            }
        });
        this.ˊ.registerReceiver(this.ʼ, new IntentFilter(ccv.ˋ()));
        return true;
    }

    protected String ᐝ() {
        return "02";
    }

    private void ˏ(Context context) {
        if (this.ˏ == null) {
            cwr.ॱ.ˋ("WeixinFriendsShare", "The api is null.");
        } else if (this.ˏ.isWXAppInstalled()) {
            cxi$d ᐝॱ = this.ˊ.ᐝॱ();
            if (ᐝॱ.ˏ()) {
                Bitmap ॱ = ᐝॱ.ॱ();
                if (ॱ == null) {
                    ॱ = cxw.ॱ(context, this.ˋ.ˏ());
                }
                new e(this, context, ॱ(ॱ)).execute(new Void[0]);
                return;
            }
            cwr.ॱ.ˋ("WeixinFriendsShare", "App Icon loading.");
            this.ˎ = true;
            this.ˊ.ͺ();
        } else {
            cwr.ॱ.ˋ("WeixinFriendsShare", "The isWXAppInstalled() is false.");
        }
    }

    protected Bitmap ॱ(Bitmap bitmap) {
        cwr.ॱ.ˋ("WeixinFriendsShare", "click share to weixin!");
        return bitmap;
    }

    private void ॱ(Context context, byte[] bArr) {
        cjo wXEntryActivityProtocol = new WXEntryActivityProtocol();
        Request request = new Request();
        request.ˋ(this.ˋ.ॱ());
        request.ˎ(ˋ(context));
        request.ˊ(bArr);
        request.ॱ(cxw.ॱ(context, this.ˋ.ʻ(), ʽ()));
        request.ˏ(ॱॱ());
        if (this.ˊ.ᐝ() instanceof Activity) {
            request.ˊ(dgm.ˎ((Activity) this.ˊ.ᐝ()));
        }
        wXEntryActivityProtocol.ॱ(request);
        cjk.ˎ().ˋ(context, new cjm("wx_entry.activity", wXEntryActivityProtocol));
        this.ˊ.finish();
    }

    protected int ॱॱ() {
        return 0;
    }

    protected String ʽ() {
        return "weixin";
    }

    private String ˋ(Context context) {
        if (this.ˋ.ˊॱ() == 3 && !TextUtils.isEmpty(this.ˋ.ˊ())) {
            return this.ˋ.ˊ();
        }
        if (!"appdetail".equals(this.ˋ.ʼ())) {
            return this.ˋ.ˊ();
        }
        return context.getString(i.ˊˊ, new Object[]{cwv.ॱ().ˋ()});
    }

    private void ॱ(Context context) {
        cke ॱ = this.ॱ.ॱ();
        for (View view : this.ˊ.ˊ(ˎ())) {
            if (view != this.ॱ) {
                view.setVisibility(8);
            }
        }
        if (ॱ == cke.ˊ) {
            cwm.ˊ().ˊ(ˎ(), new cwx(this) {
                final /* synthetic */ cxn ˎ;

                {
                    this.ˎ = r1;
                }

                public void ˊ(cwy o_cwy) {
                    if (o_cwy != null) {
                        BaseDistCardBean baseDistCardBean = new BaseDistCardBean();
                        baseDistCardBean.ˏॱ(o_cwy.ˋ());
                        baseDistCardBean.ˋॱ(o_cwy.ॱॱ());
                        baseDistCardBean.ˏˎ(o_cwy.ˊ());
                        baseDistCardBean.ˋ(o_cwy.ʻ());
                        baseDistCardBean.ˋᐝ(o_cwy.ॱ());
                        try {
                            baseDistCardBean.ॱ(Long.parseLong(o_cwy.ˏ()));
                        } catch (NumberFormatException e) {
                            cwr.ॱ.ˊ("WeixinFriendsShare", "error size:" + o_cwy.ˏ());
                        }
                        baseDistCardBean.ˉ(o_cwy.ᐝ());
                        baseDistCardBean.ॱ(o_cwy.ʽ());
                        baseDistCardBean.ˎ(o_cwy.ˎ());
                        baseDistCardBean.ॱ(o_cwy.ʼ());
                        baseDistCardBean.ͺ(o_cwy.ˋॱ());
                        this.ˎ.ॱ.setParam(baseDistCardBean);
                        if (!this.ˎ.ˋ(this.ˎ.ॱ)) {
                            this.ˎ.ॱ.setVisibility(0);
                        }
                        this.ˎ.ॱ.ॱ();
                    }
                }
            });
        } else {
            this.ॱ.setVisibility(0);
            this.ॱ.ॱ();
        }
        evk.ˏ(context, i.ˊᐝ, 1).ˋ();
    }

    private boolean ˋ(DownloadButton downloadButton) {
        for (View view : this.ˊ.ˊ(ˎ())) {
            if (view != downloadButton && view.getVisibility() == 0) {
                return true;
            }
        }
        return false;
    }

    private void ʼ() {
        if (this.ˏ == null) {
            if (TextUtils.isEmpty(this.ʻ)) {
                cwr.ॱ.ˊ("WeixinFriendsShare", "error appKey:" + this.ʻ);
                return;
            }
            this.ˏ = WXAPIFactory.createWXAPI(ContentManager.getInstant().getContext(), this.ʻ);
            this.ˏ.registerApp(this.ʻ);
            cwr.ॱ.ˋ("WeixinFriendsShare", "init weixin api !");
        }
    }

    public void ˎ(ShareBean shareBean) {
        if (this.ˏ != null) {
            this.ˏ.detach();
            this.ˏ = null;
        }
        this.ˊ.unregisterReceiver(this.ʼ);
    }

    public void ˏ() {
        this.ˎ = false;
    }

    public void ॱ() {
        if (this.ˎ) {
            ˏ(this.ˊ.ᐝ());
        }
    }
}
